home *** CD-ROM | disk | FTP | other *** search
/ CD Ware Multimedia 1995 May / cd Ware (Juegos) Epimundo.iso / DOS / C / WLIB.ZIP / WMISC.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-13  |  5.6 KB  |  183 lines

  1. #ifndef WMiscIncluded
  2. #define WMiscIncluded
  3.  
  4. // copyright (c) 1992, 1993 by Paul Wheaton
  5. // 1916 Brooks #205, Missoula, MT  59801
  6. //
  7. //       phone:  (406)543-1928
  8. //  CompuServe:  72707,207
  9. //    Internet:  72707.207@CompuServe.com
  10.  
  11. // one big header file for miscelaneous odds n ends
  12. // this file is generally included by all other header files
  13.  
  14. // these types are for readability or for making sure that you
  15. // use the same size of integral storage across platforms
  16. typedef unsigned char  Bool;
  17. typedef unsigned char  Byte;
  18. typedef signed   char  SByte;
  19. typedef unsigned short Word;
  20. typedef signed   short SWord;
  21. typedef unsigned long  Long;
  22. typedef signed   long  SLong;
  23. typedef unsigned int   UInt;
  24.  
  25. typedef char* CharStar;  // has to be fed to some macros
  26.  
  27. // constants related to above types.  The Size of these things will stay the
  28. // same from system to system.
  29.  
  30. const char  MaxChar  = 255;
  31. const Byte  MaxByte  = 255;
  32. const SByte MaxSByte = 127;
  33. const SByte MinSByte = (-128);
  34. const Word  MaxWord  = 0xFFFF;
  35. const SWord MaxSWord = 32767;
  36. const SWord MinSWord = 0x8000; // (-32768);
  37. const IntLen=sizeof(int);
  38. #if IntLen==2
  39.   const int   MaxInt   = 32767;
  40.   const int   MinInt   = 0x8000; // (-32768);
  41.   const UInt  MaxUInt  = 0xFFFF;
  42. #else
  43.   const int   MaxInt   = 0x7FFFFFFFL; // 2147483647;
  44.   const int   MinInt   = 0x80000000L; // (-2147483648);
  45.   const UInt  MaxUInt  = 0xFFFFFFFFL;
  46. #endif
  47. const SLong MaxSLong = 0x7FFFFFFFL; // 2147483647;
  48. const Long  MaxLong  = 0xFFFFFFFFL;
  49. const SLong MinSLong = 0x80000000L; // (-2147483648);
  50.  
  51. const long AMillion=1000000L;
  52. const long ABillion=1000000000L;
  53.  
  54. const Bool True  = 1;
  55. const Bool False = 0;
  56. const Bool Yes   = 1;
  57. const Bool No    = 0;
  58. const Bool On    = 1;
  59. const Bool Off   = 0;
  60.  
  61. /* the following have values < 0 so that they may be used as alternatives to
  62.    text placement rountines that need positive values */
  63.  
  64. const int Left=(MinInt+1);
  65. const int Center=(MinInt+2);
  66. const int Right=(MinInt+3);
  67.  
  68. const int NotFound=-1;
  69. //const long VecObjNotFound=-1;
  70.   // used with some search functions.
  71.  
  72. /* misc. macros */
  73.  
  74. SByte  Abs(SByte  x);
  75. SWord  Abs(SWord  x);
  76. int    Abs(int    x);
  77. SLong  Abs(SLong  x);
  78. float  Abs(float  x);
  79. double Abs(double x);
  80.  
  81. Byte   Max(Byte   a, Byte b  );
  82. SByte  Max(SByte  a, SByte b );
  83. Word   Max(Word   a, Word b  );
  84. SWord  Max(SWord  a, SWord b );
  85. int    Max(int    a, int b   );
  86. UInt   Max(UInt   a, UInt b  );
  87. Long   Max(Long   a, Long b  );
  88. SLong  Max(SLong  a, SLong b );
  89. double Max(double a, double b);
  90.  
  91. Byte   Min(Byte   a, Byte b  );
  92. SByte  Min(SByte  a, SByte b );
  93. Word   Min(Word   a, Word b  );
  94. SWord  Min(SWord  a, SWord b );
  95. int    Min(int    a, int b   );
  96. UInt   Min(UInt   a, UInt b  );
  97. Long   Min(Long   a, Long b  );
  98. SLong  Min(SLong  a, SLong b );
  99. double Min(double a, double b);
  100.  
  101. Bool InRange(Byte   Val, Byte   Low, Byte   High);
  102. Bool InRange(SByte  Val, SByte  Low, SByte  High);
  103. Bool InRange(Word   Val, Word   Low, Word   High);
  104. Bool InRange(SWord  Val, SWord  Low, SWord  High);
  105. Bool InRange(int    Val, int    Low, int    High);
  106. Bool InRange(UInt   Val, UInt   Low, UInt   High);
  107. Bool InRange(Long   Val, Long   Low, Long   High);
  108. Bool InRange(SLong  Val, SLong  Low, SLong  High);
  109. Bool InRange(double Val, double Low, double High);
  110. Bool InRange(long double Val, long double Low, long double High);
  111.  
  112. SLong Round(double Val);      //  .2 => 0    .7 => 1    -.2 => 0    -.7 => -1
  113. SLong RoundUp(double Val);    //  .2 => 1    .7 => 1    -.2 => 0    -.7 => 0
  114. SLong RoundDown(double Val);  //  .2 => 0    .7 => 0    -.2 => -1   -.7 => -1
  115. SLong RoundOut(double Val);   //  .2 => 1    .7 => 1    -.2 => -1   -.7 => -1
  116. SLong RoundIn(double Val);     //  .2 => 0    .7 => 0    -.2 => 0    -.7 => 0
  117.  
  118. char ToUpper(char C);
  119. char ToLower(char C);
  120.  
  121. void PigeonHole(Long TotQuan, int ArrayLen, int A[]);
  122.   // spreads TotQuan as evenly as possible over A
  123.  
  124. Long SystemTick(); // returns the current system tick
  125.  
  126. #include <dos.h>
  127.  
  128. #ifndef MAJORBBS
  129.  
  130.   inline void Delay(int MilliSecs) {delay(MilliSecs);}
  131.  
  132.   void Sound(float Pitch,int MilliSecs);
  133.     // a little bit of control over the pc speaker
  134.  
  135.   void Beep(int Num=1);
  136.     // Num is the number of beeps ya want
  137.  
  138. #endif
  139.  
  140. #define Randomize() srand((int) time(NULL))
  141.   // Initializes (seeds) the random number generator
  142.  
  143. #define Random(Max) (int(rand() % Max))
  144.   // returns a random integer in the range of 0 to Max excluding Max
  145.  
  146. #define DebugPause(Msg)  {puts(Msg "\n"); Delay(2500); }
  147.   // prints the message and then pauses a bit.  Used in debugging
  148.  
  149. #define CopyArray(Dest,Source) memcpy(Dest,Source,sizeof(Dest))
  150.   // Dest must be something that sizeof will work on
  151.  
  152. #define CopyString(Dest,Source) (strncpy(Dest,Source,sizeof(Dest)-1),Dest[sizeof(Dest)-1]=0)
  153.   // For the type (Char*,Char*) Dest must be something that sizeof will work on
  154.  
  155. #define ClearStruct(A) memset((void*)(&A),0,sizeof(A))
  156.   // fill a struct with zeros
  157.  
  158. #define ClearArray(A) memset(A,0,sizeof(A))
  159.   /* fill an array with zeros.  Array must be defined so that sizeof will
  160.      work on it */
  161.  
  162. // Given these objects, standard CRC16 will be calculated
  163. Word CRC(void* P,Long Size);
  164. Word CRC(const char* S);
  165.  
  166. #define Loop while(1)
  167.   // structure for an infinite loop
  168.  
  169. #define For(TheVar,TheEnd)  for(TheVar=0;TheVar<TheEnd;TheVar++)
  170.   // Makes for a simpler, more readable, less error prone loop.
  171.   // Use  "For(I,10)" instead of "for(I=0;I<10;I++)"
  172.  
  173. typedef void (* VoidFuncPtr)(void);
  174. typedef Bool (* BoolFuncPtr)(void);
  175. typedef void (* VoidFuncCharPtr)(char);
  176.  
  177. void BigMemCopy(void* Dest, const void* Source, long Size);
  178.  
  179. void FatalError(const char*);
  180.  
  181. #endif
  182.  
  183.